#!/usr/bin/env node

// console.log(process.argv)
let url="http://api.tianapi.com/txapi/xingzuo/index?key=1d89bae77797cf1c4469e459bc46e469&me="
let url1="http://fanyi.youdao.com/openapi.do?keyfrom=toaijf&key=868480929&type=data&doctype=json&version=1.1&q="
let agrs=process.argv[2]
let axios=require('axios')
let chalk=require('chalk')//npm i chalk 下载颜色插件

axios.get(url+encodeURI(agrs)).then(res=>{
    // console.log(res.data)
    let text=''
    if(res.data.code==200){
        let obj=res.data.newslist[0]
        for(let i in obj){
            text+=`${chalk.yellow(i)}: ${chalk.green(obj[i])}\n\n`// \n换行符
        }
    }
    console.log(text)
})

//翻译命令行工具
axios.get(url1+encodeURI(agrs)).then(res=>{
    // console.log(res.data)
    let text1=''
    if(res.data.errorCode==0){
        let arr=res.data.web
        arr.forEach(item=>{
            text1+=`${chalk.yellow(item.key)}: ${chalk.green(item.value.join(' '))}\n\n`// \n换行符
        })
    }
    console.log(text1)
})